home *** CD-ROM | disk | FTP | other *** search
/ Champak 140 / (Vol 140) Sep 19 2011.iso / Games / top_that_pizza.swf / scripts / FSelectableListSymbol.as < prev    next >
Text File  |  2011-09-19  |  12KB  |  388 lines

  1. function FSelectableListClass()
  2. {
  3.    this.init();
  4. }
  5. FSelectableListClass.prototype = new FUIComponentClass();
  6. FSelectableListClass.prototype.init = function()
  7. {
  8.    var _loc1_ = this;
  9.    super.init();
  10.    _loc1_.enable = true;
  11.    _loc1_.selected = new Array();
  12.    _loc1_.topDisplayed = _loc1_.numDisplayed = 0;
  13.    _loc1_.lastSelected = 0;
  14.    _loc1_.tabChildren = false;
  15.    if(_loc1_._name != undefined)
  16.    {
  17.       _loc1_.dataProvider = new DataProviderClass();
  18.       _loc1_.dataProvider.addView(_loc1_);
  19.    }
  20. };
  21. FSelectableListClass.prototype.addItemAt = function(index, label, data)
  22. {
  23.    if(index < 0 || !this.enable)
  24.    {
  25.       return undefined;
  26.    }
  27.    this.dataProvider.addItemAt(index,{label:label,data:data});
  28. };
  29. FSelectableListClass.prototype.addItem = function(label, data)
  30. {
  31.    if(!this.enable)
  32.    {
  33.       return undefined;
  34.    }
  35.    this.dataProvider.addItem({label:label,data:data});
  36. };
  37. FSelectableListClass.prototype.removeItemAt = function(index)
  38. {
  39.    var _loc1_ = this;
  40.    _loc1_.selectHolder = _loc1_.getSelectedIndex();
  41.    var _loc2_ = _loc1_.getItemAt(index);
  42.    _loc1_.dataProvider.removeItemAt(index);
  43.    return _loc2_;
  44. };
  45. FSelectableListClass.prototype.removeAll = function()
  46. {
  47.    this.dataProvider.removeAll();
  48. };
  49. FSelectableListClass.prototype.replaceItemAt = function(index, newLabel, newData)
  50. {
  51.    this.dataProvider.replaceItemAt(index,{label:newLabel,data:newData});
  52. };
  53. FSelectableListClass.prototype.sortItemsBy = function(fieldName, order)
  54. {
  55.    var _loc1_ = this;
  56.    _loc1_.lastSelID = _loc1_.dataProvider.getItemID(_loc1_.lastSelected);
  57.    _loc1_.dataProvider.sortItemsBy(fieldName,order);
  58. };
  59. FSelectableListClass.prototype.getLength = function()
  60. {
  61.    return this.dataProvider.getLength();
  62. };
  63. FSelectableListClass.prototype.getSelectedIndex = function()
  64. {
  65.    var _loc2_ = this;
  66.    for(var _loc3_ in _loc2_.selected)
  67.    {
  68.       var _loc1_ = _loc2_.selected[_loc3_].sIndex;
  69.       if(_loc1_ != undefined)
  70.       {
  71.          return _loc1_;
  72.       }
  73.    }
  74. };
  75. FSelectableListClass.prototype.getSelectedItem = function()
  76. {
  77.    return this.getItemAt(this.getSelectedIndex());
  78. };
  79. FSelectableListClass.prototype.getItemAt = function(index)
  80. {
  81.    return this.dataProvider.getItemAt(index);
  82. };
  83. FSelectableListClass.prototype.getEnabled = function()
  84. {
  85.    return this.enable;
  86. };
  87. FSelectableListClass.prototype.getValue = function()
  88. {
  89.    var _loc1_ = this.getSelectedItem();
  90.    if(_loc1_.data != undefined)
  91.    {
  92.       return _loc1_.data;
  93.    }
  94.    return _loc1_.label;
  95. };
  96. FSelectableListClass.prototype.setSelectedIndex = function(index, flag)
  97. {
  98.    var _loc1_ = this;
  99.    var _loc2_ = index;
  100.    if(_loc2_ >= 0 && _loc2_ < _loc1_.getLength() && _loc1_.enable)
  101.    {
  102.       _loc1_.clearSelected();
  103.       _loc1_.selectItem(_loc2_,true);
  104.       _loc1_.lastSelected = _loc2_;
  105.       _loc1_.invalidate("updateControl");
  106.       if(flag != false)
  107.       {
  108.          _loc1_.executeCallBack();
  109.       }
  110.    }
  111. };
  112. FSelectableListClass.prototype.setDataProvider = function(obj)
  113. {
  114.    var _loc2_ = obj;
  115.    this.setScrollPosition(0);
  116.    this.clearSelected();
  117.    if(_loc2_ instanceof Array)
  118.    {
  119.       this.dataProvider = new DataProviderClass();
  120.       var _loc1_ = 0;
  121.       while(_loc1_ < _loc2_.length)
  122.       {
  123.          var _loc3_ = typeof _loc2_[_loc1_] != "string" ? _loc2_[_loc1_] : {label:_loc2_[_loc1_]};
  124.          this.dataProvider.addItem(_loc3_);
  125.          _loc1_ = _loc1_ + 1;
  126.       }
  127.    }
  128.    else
  129.    {
  130.       this.dataProvider = _loc2_;
  131.    }
  132.    this.dataProvider.addView(this);
  133. };
  134. FSelectableListClass.prototype.setItemSymbol = function(linkID)
  135. {
  136.    var _loc1_ = this;
  137.    _loc1_.tmpPos = _loc1_.getScrollPosition();
  138.    _loc1_.itemSymbol = linkID;
  139.    _loc1_.invalidate("setSize");
  140.    _loc1_.setScrollPosition(_loc1_.tmpPos);
  141. };
  142. FSelectableListClass.prototype.setEnabled = function(enabledFlag)
  143. {
  144.    var _loc2_ = this;
  145.    _loc2_.cleanUI();
  146.    super.setEnabled(enabledFlag);
  147.    _loc2_.enable = enabledFlag;
  148.    _loc2_.boundingBox_mc.gotoAndStop(!_loc2_.enable ? "disabled" : "enabled");
  149.    var _loc3_ = Math.min(_loc2_.numDisplayed,_loc2_.getLength());
  150.    var _loc1_ = 0;
  151.    while(_loc1_ < _loc3_)
  152.    {
  153.       _loc2_.container_mc["fListItem" + _loc1_ + "_mc"].setEnabled(_loc2_.enable);
  154.       _loc1_ = _loc1_ + 1;
  155.    }
  156.    if(_loc2_.enable)
  157.    {
  158.       _loc2_.invalidate("updateControl");
  159.    }
  160. };
  161. FSelectableListClass.prototype.updateControl = function()
  162. {
  163.    var _loc2_ = this;
  164.    var _loc1_ = 0;
  165.    while(_loc1_ < _loc2_.numDisplayed)
  166.    {
  167.       _loc2_.container_mc["fListItem" + _loc1_ + "_mc"].drawItem(_loc2_.getItemAt(_loc2_.topDisplayed + _loc1_),_loc2_.isSelected(_loc2_.topDisplayed + _loc1_));
  168.       _loc1_ = _loc1_ + 1;
  169.    }
  170. };
  171. FSelectableListClass.prototype.setSize = function(w, h)
  172. {
  173.    var _loc1_ = this;
  174.    super.setSize(w,h);
  175.    _loc1_.boundingBox_mc._xscale = _loc1_.boundingBox_mc._yscale = 100;
  176.    _loc1_.boundingBox_mc._xscale = _loc1_.width * 100 / _loc1_.boundingBox_mc._width;
  177.    _loc1_.boundingBox_mc._yscale = _loc1_.height * 100 / _loc1_.boundingBox_mc._height;
  178.    var _loc2_ = 0;
  179.    while(_loc2_ < _loc1_.numDisplayed)
  180.    {
  181.       _loc1_.container_mc.attachMovie(_loc1_.itemSymbol,"fListItem" + _loc2_ + "_mc",10 + _loc2_,{controller:_loc1_,itemNum:_loc2_});
  182.       var _loc3_ = _loc1_.container_mc["fListItem" + _loc2_ + "_mc"];
  183.       var offset = _loc1_.scrollOffset != undefined ? _loc1_.scrollOffset : 0;
  184.       _loc3_.setSize(_loc1_.width - offset,_loc1_.itmHgt);
  185.       _loc3_._y = (_loc1_.itmHgt - 2) * _loc2_;
  186.       _loc2_ = _loc2_ + 1;
  187.    }
  188.    _loc1_.updateControl();
  189. };
  190. FSelectableListClass.prototype.modelChanged = function(eventObj)
  191. {
  192.    var _loc1_ = this;
  193.    var firstRow = eventObj.firstRow;
  194.    var lastRow = eventObj.lastRow;
  195.    var event = eventObj.event;
  196.    if(event == "addRows")
  197.    {
  198.       for(var _loc2_ in _loc1_.selected)
  199.       {
  200.          if(_loc1_.selected[_loc2_].sIndex != undefined && _loc1_.selected[_loc2_].sIndex >= firstRow)
  201.          {
  202.             _loc1_.selected[_loc2_].sIndex += lastRow - firstRow + 1;
  203.             _loc1_.setSelectedIndex(_loc1_.selected[_loc2_].sIndex,false);
  204.          }
  205.       }
  206.    }
  207.    else if(event == "deleteRows")
  208.    {
  209.       if(firstRow == lastRow)
  210.       {
  211.          var index = firstRow;
  212.          if(_loc1_.selectHolder == index)
  213.          {
  214.             _loc1_.selectionDeleted = true;
  215.          }
  216.          if(_loc1_.topDisplayed + _loc1_.numDisplayed >= _loc1_.getLength() && _loc1_.topDisplayed > 0)
  217.          {
  218.             _loc1_.topDisplayed = _loc1_.topDisplayed - 1;
  219.             if(_loc1_.selectionDeleted && index - 1 >= 0)
  220.             {
  221.                _loc1_.setSelectedIndex(index - 1,false);
  222.             }
  223.          }
  224.          else if(_loc1_.selectionDeleted)
  225.          {
  226.             var len = _loc1_.getLength();
  227.             if(index == len - 1 && len > 1 || index > len / 2)
  228.             {
  229.                _loc1_.setSelectedIndex(index - 1,false);
  230.             }
  231.             else
  232.             {
  233.                _loc1_.setSelectedIndex(index,false);
  234.             }
  235.          }
  236.          for(_loc2_ in _loc1_.selected)
  237.          {
  238.             if(_loc1_.selected[_loc2_].sIndex > firstRow)
  239.             {
  240.                _loc1_.selected[_loc2_].sIndex--;
  241.             }
  242.          }
  243.       }
  244.       else
  245.       {
  246.          _loc1_.clearSelected();
  247.          _loc1_.topDisplayed = 0;
  248.       }
  249.    }
  250.    else if(event == "sort")
  251.    {
  252.       var len = _loc1_.getLength();
  253.       _loc2_ = 0;
  254.       while(_loc2_ < len)
  255.       {
  256.          if(_loc1_.isSelected(_loc2_))
  257.          {
  258.             var _loc3_ = _loc1_.dataProvider.getItemID(_loc2_);
  259.             if(_loc3_ == _loc1_.lastSelID)
  260.             {
  261.                _loc1_.lastSelected = _loc2_;
  262.             }
  263.             _loc1_.selected[String(_loc3_)].sIndex = _loc2_;
  264.          }
  265.          _loc2_ = _loc2_ + 1;
  266.       }
  267.    }
  268.    _loc1_.invalidate("updateControl");
  269. };
  270. FSelectableListClass.prototype.measureItmHgt = function()
  271. {
  272.    var _loc1_ = this;
  273.    _loc1_.attachMovie(_loc1_.itemSymbol,"tmpItem_mc",0,{controller:_loc1_});
  274.    _loc1_.tmpItem_mc.drawItem({label:"Sizer: PjtTopg"},false);
  275.    _loc1_.itmHgt = _loc1_.tmpItem_mc._height;
  276.    _loc1_.tmpItem_mc.removeMovieClip();
  277. };
  278. FSelectableListClass.prototype.selectItem = function(index, selectedFlag)
  279. {
  280.    var _loc1_ = this;
  281.    var _loc2_ = index;
  282.    if(selectedFlag && !_loc1_.isSelected(_loc2_))
  283.    {
  284.       _loc1_.selected[String(_loc1_.dataProvider.getItemID(_loc2_))] = {sIndex:_loc2_};
  285.    }
  286.    else if(!selectedFlag)
  287.    {
  288.       delete _loc1_.selected[String(_loc1_.dataProvider.getItemID(_loc2_))];
  289.    }
  290. };
  291. FSelectableListClass.prototype.isSelected = function(index)
  292. {
  293.    return this.selected[String(this.dataProvider.getItemID(index))].sIndex != undefined;
  294. };
  295. FSelectableListClass.prototype.clearSelected = function()
  296. {
  297.    var _loc1_ = this;
  298.    for(var _loc3_ in _loc1_.selected)
  299.    {
  300.       var _loc2_ = _loc1_.selected[_loc3_].sIndex;
  301.       if(_loc2_ != undefined && _loc1_.topDisplayed <= _loc2_ && _loc2_ < _loc1_.topDisplayed + _loc1_.numDisplayed)
  302.       {
  303.          _loc1_.container_mc["fListItem" + (_loc2_ - _loc1_.topDisplayed) + "_mc"].drawItem(_loc1_.getItemAt(_loc2_),false);
  304.       }
  305.    }
  306.    delete _loc1_.selected;
  307.    _loc1_.selected = new Array();
  308. };
  309. FSelectableListClass.prototype.selectionHandler = function(itemNum)
  310. {
  311.    var _loc1_ = this;
  312.    var _loc2_ = _loc1_.topDisplayed + itemNum;
  313.    if(_loc1_.getItemAt(_loc2_ == undefined))
  314.    {
  315.       _loc1_.changeFlag = false;
  316.    }
  317.    else
  318.    {
  319.       _loc1_.changeFlag = true;
  320.       _loc1_.clearSelected();
  321.       _loc1_.selectItem(_loc2_,true);
  322.       _loc1_.container_mc["fListItem" + itemNum + "_mc"].drawItem(_loc1_.getItemAt(_loc2_),_loc1_.isSelected(_loc2_));
  323.    }
  324. };
  325. FSelectableListClass.prototype.moveSelBy = function(incr)
  326. {
  327.    var _loc1_ = this;
  328.    var _loc3_ = _loc1_.getSelectedIndex();
  329.    var _loc2_ = _loc3_ + incr;
  330.    _loc2_ = Math.max(0,_loc2_);
  331.    _loc2_ = Math.min(_loc1_.getLength() - 1,_loc2_);
  332.    if(_loc2_ != _loc3_)
  333.    {
  334.       if(_loc3_ < _loc1_.topDisplayed || _loc3_ >= _loc1_.topDisplayed + _loc1_.numDisplayed)
  335.       {
  336.          _loc1_.setScrollPosition(_loc3_);
  337.       }
  338.       if(_loc2_ >= _loc1_.topDisplayed + _loc1_.numDisplayed || _loc2_ < _loc1_.topDisplayed)
  339.       {
  340.          _loc1_.setScrollPosition(_loc1_.topDisplayed + incr);
  341.       }
  342.       _loc1_.selectionHandler(_loc2_ - _loc1_.topDisplayed);
  343.    }
  344. };
  345. FSelectableListClass.prototype.clickHandler = function(itmNum)
  346. {
  347.    var _loc1_ = this;
  348.    _loc1_.focusRect.removeMovieClip();
  349.    if(!_loc1_.focused)
  350.    {
  351.       _loc1_.pressFocus();
  352.    }
  353.    _loc1_.selectionHandler(itmNum);
  354.    _loc1_.onMouseUp = _loc1_.releaseHandler;
  355. };
  356. FSelectableListClass.prototype.releaseHandler = function()
  357. {
  358.    var _loc1_ = this;
  359.    if(_loc1_.changeFlag)
  360.    {
  361.       _loc1_.executeCallBack();
  362.    }
  363.    _loc1_.changeFlag = false;
  364.    _loc1_.onMouseUp = undefined;
  365. };
  366. FSelectableListClass.prototype.myOnSetFocus = function()
  367. {
  368.    var _loc2_ = this;
  369.    super.myOnSetFocus();
  370.    var _loc1_ = 0;
  371.    while(_loc1_ < _loc2_.numDisplayed)
  372.    {
  373.       _loc2_.container_mc["fListItem" + _loc1_ + "_mc"].highlight_mc.gotoAndStop("enabled");
  374.       _loc1_ = _loc1_ + 1;
  375.    }
  376. };
  377. FSelectableListClass.prototype.myOnKillFocus = function()
  378. {
  379.    var _loc2_ = this;
  380.    super.myOnKillFocus();
  381.    var _loc1_ = 0;
  382.    while(_loc1_ < _loc2_.numDisplayed)
  383.    {
  384.       _loc2_.container_mc["fListItem" + _loc1_ + "_mc"].highlight_mc.gotoAndStop("unfocused");
  385.       _loc1_ = _loc1_ + 1;
  386.    }
  387. };
  388.